package com.syf.controller.RJController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syf.cmd.SelByIDCmd;
import com.syf.domain.store.BsSoftwareRelease;
import com.syf.domain.store.BsSoftwareUpdata;
import com.syf.model.R;
import com.syf.service.BsSoftwareUpdataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author syf
 * @create 2022-02-08 9:32
 */
@RestController
@RequestMapping("/softwareUpdata")
@Api(tags = "应用的更新包和更新记录")
public class BsSoftwareUpdataController {

    @Autowired
    private BsSoftwareUpdataService bsSoftwareUpdataService;


    /**
     * 1.添加一条升级记录
     * 2.修改应用版本
     * @param bsSoftwareUpdata
     * @return
     */
    @PostMapping("/addSoftUpdata")
    @CrossOrigin
    @ApiOperation(value = "上传更新包进行软件升级")
    public R add(@RequestBody @Validated BsSoftwareUpdata bsSoftwareUpdata){
        bsSoftwareUpdata.setNewMbSize(bsSoftwareUpdata.getNewMbSize()+"MB");
        boolean save = bsSoftwareUpdataService.uploadSoftUpdata(bsSoftwareUpdata);
        if(save){
            return R.ok("更新成功") ;
        }
        return  R.fail("更新失败") ;
    }


    /**
     * 查看更新记录
     * @return
     */
    @PostMapping("/softUpdataList")
    @CrossOrigin
    @ApiOperation(value = "分页条件查询--更新包(/更新记录)列表")
    public R<List<BsSoftwareUpdata>> softUpdataList(@RequestBody SelByIDCmd selByIDCmd){
        List<BsSoftwareUpdata> list =  bsSoftwareUpdataService.selList(selByIDCmd.getSoftwareCode());
        return R.ok(list) ;
    }


}
